import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: (resolve) => {
      import('../view/Home.vue').then(resolve)
    },
    children: [
      {  // 请假管理
        path: '/sendLeave',
        component: (resolve) => {
          import('../view/leaveManage/sendLeave.vue').then(resolve)
        }
      }, {
        path: '/approvalLeave',
        component: (resolve) => {
          import('../view/leaveManage/approvalLeave.vue').then(resolve)
        }
      }, {
        path: '/leaveList',
        component: (resolve) => {
          import('../view/leaveManage/leaveList.vue').then(resolve)
        }
      }, { // 用户管理
        path: '/userInfo',
        component: (resolve) => {
          import('../view/user/UserInfo.vue').then(resolve)
        }
      }, {
        path: '/userQuery',
        component: (resolve) => {
          import('../view/user/UserQuery.vue').then(resolve)
        }
      },
      {
        path: '/holiday',
        component: (resolve) => {
          import('../view/holiday/Holiday.vue').then(resolve)
        }
      }
    ]
  }, {
    path: '*',
    component: {
      render(h) {
        return h('div', {
          staticClass: 'flex flex-main-center',
          attrs: {
            style: 'width:100%;font-size:32px'
          }
        }, '未找到哦')
      }
    }
  }
]

const router = new VueRouter({
  linkActiveClass: 'active',
  mode: 'history',
  scrollBehavior: () => ({
    y: 0
  }),
  routes
})

router.beforeEach((to, from, next) => {
  next()
})

export default router
